
function hide2border(devHeader) {
    if (!($("." + devHeader + " .searchList>li").length)) {
        $("." + devHeader + " .searchList").hide();
    } else {
        $("." + devHeader + " .searchList").show();
    }
}
function searchFunc(devHeader) {
    var timeoutflag = null;
    //直接输入地址查询
    $("." + devHeader + " .search-btn").on("click", function () {
        //var devType = "smokeDetector";
        //devType = "manholeCover";
        //devType = "streetLamp";
        //devType = "camera";

        //防止多次搜索
        if (timeoutflag != null) {
            clearTimeout(timeoutflag);
            timeoutflag = null;
        } else {
            timeoutflag = setTimeout(function () {
                var searchContent = $("." + devHeader + " .searchBox input").val();
                //内容存在则搜索
                if (searchContent) {
                    $.ajax({
                        url: "/device/data/list/bydeviceTypeandaddresslike/" + devTypeId + "/" + searchContent+"/byuser",
                        type: "GET",
                        async: false,
                        success: function (result) {

                            if (result.status == "200") {
                                for (var i = 0; i < result.data.length; i++) {
                                    var searchAddress = result.data[i].address;
                                    var latitude = result.data[i].latitude;
                                    var longitude = result.data[i].longitude;
                                    var devCode = result.data[i].devCode;
                                    if (searchContent == searchAddress) {
                                        map.setZoom(20);
                                        BaiDuMap.panTo(latitude, longitude);
                                        //	 地图信息框显示
                                        $('.BMap_pop').parent().show();
                                        $(".BMap_shadow").parent().show();
                                        BaiDuMap.popMenu(devCode);
                                        $("." + devHeader + " .searchList").html("");//hide
                                    } else {

                                    }
                                }
                            } else {

                            }
                        }

                    });
                }
                timeoutflag = null;
            }, 500);
        }
        return false;
    });

    //模糊查询

    $("." + devHeader + " .searchBox input").on("input", function (e) {
        $("." + devHeader + " .searchList").show();
        hide2border(devHeader);
        if ($("." + devHeader + " .searchList li")) {//键盘抬起后就判断页面中是否存在这个元素,存在就删除
            $("." + devHeader + " .searchList li").remove();
        }
        var searchContent = $("." + devHeader + " .searchBox input").val();
        //查询内容存在则搜索
        if (searchContent) {
            $.ajax({
                url: "/device/data/list/bydeviceTypeandaddresslike/" + devTypeId + "/" + searchContent + "/byuser",
                type: "GET",
                async: false,
                success: function (result) {

                    if (result.status == "200") {
                        for (var i = 0; i < result.data.length; i++) {
                            var searchAddress = result.data[i].address;
                            var latitude = result.data[i].latitude;
                            var longitude = result.data[i].longitude;
                            var devCode = result.data[i].devCode;
                            console.log(result)
                            if (searchAddress) {
                                $("." + devHeader + " .searchList").append('<li devicecode="' + devCode + '" longitude="' + longitude + '" latitude="' + latitude + '"><i class="fa fa-map-marker"></i>' + searchAddress + '</li>');
//                                定位时单个点筛选
//                                $(".searchBox #search-btn").attr("devicecode",devCode);
//                                $(".searchBox #search-btn").attr("longitude",longitude);
//                               $(".searchBox #search-btn").attr("latitude",latitude);
                                hide2border(devHeader);
                            }
                        }
                    } else {
                                
                    }
                }
            });

        }else{
//        	去掉定位按钮的属性
//            $(".searchBox #search-btn").removeAttr("devicecode");
//            $(".searchBox #search-btn").removeAttr("longitude");
//            $(".searchBox #search-btn").removeAttr("latitude");
        	
        }
        $("." + devHeader + " .searchList").show();
        hide2border(devHeader);
    });
    //直接输入地址,点击列表查询
    $("." + devHeader + " .searchList").on("click", "li", function () {
        $("." + devHeader + " .searchList").show();
        var liVal = $(this).text();
        var searchVal = $("." + devHeader + " .searchBox input").val(liVal);

        $("." + devHeader + " .searchList").html("");//hide
        var li = $(this);
        var devicecode = li.attr("devicecode");
        var latitude = li.attr("latitude");
        var longitude = li.attr("longitude");
        map.setZoom(20);
        BaiDuMap.panTo(latitude, longitude);
//        地图信息框显示
        BaiDuMap.popMenu(devicecode);
        return false;
    });
}

$(function () {
    $('.slimScrollDiv .menu').css("height", "auto");
    $(".slimScrollDiv").css("height", "auto");
    showDropdown();

 // toggle-btn 头部左侧边栏切换按钮 
    $(".sidebar-toggle").click(function () {
        $(".toggle-btn").toggleClass("on");
        $(".bottombar").toggleClass("bottombar-toggle", 400, "easeOutSine");
        if ($(".toggle-btn").hasClass("on")) {
            $(".user-panel").css({"height": "50px", "min-height": "50px"});
            $(".small-user").show();
        } else {
            $(".user-panel").css({"height": "80px", "min-height": "80px"});
            $(".small-user").hide();
        }
    });
    
//	快速定位
    $(document).on("click", function () {
        $(".searchList").hide();
    });

    /*    $('#inputAddress1').click(function() {
     if(timeoutflag != null){
     clearTimeout(timeoutflag);
     timeoutflag = null;
     }else{
     timeoutflag=setTimeout(function(){
     dosomething();
     },500);
     }
     });*/


});
//鼠标移上显示报警状态下拉框信息
function showDropdown() {
    $(".menuHover").mouseover(function () {
        $(this).find("a").attr("data-toggle", "dropdown");
        $(this).addClass("open");
    });
    $(".menuHover").mouseout(function () {
        $(this).find("a").removeAttr("data-toggle");
        $(this).removeClass("open");
    });
}


/* 点击菜单栏继续显示 */
$('.dropdown-menu').on('click', function () {
    $(this).addClass('open');
    return false;
})
// 实时显示报警信息
function alarmInfo(deviceNameAbbr, addressAbbr, returnTimesAbbr, latitudeAbbr, longitudeAbbr, devCodeAbbr, statusAbbr) {
    var alarmFaultLowHtml = '<li class="li_device" devicecode="' + devCodeAbbr + '"' +
        ' latitude = "' + latitudeAbbr + '"' +
        ' longitude = "' + longitudeAbbr + '"' +
        ' deviceStatus = "' + statusAbbr + '"' +
        '><a href="#"><div class="pull-left"><i class="fa fa-map-marker"></i></div><h4 class="deviceName" style="margin-bottom:12px">' + deviceNameAbbr + '<small><i class="fa fa-clock-o"></i>' + moment(returnTimesAbbr).format("YYYY-MM-DD HH:mm:ss") + '</small></h4><p>' + addressAbbr + '</p></a></li>';
    $('.alarmFaultLow .menu li[devicecode=' + devCodeAbbr + ']').remove();
    if (statusAbbr == 1) {
        /*火警*/
        $('.alarmMenu .menu').prepend(alarmFaultLowHtml);
    } else if (statusAbbr == 3) {
        /*故障*/
        $('.faultMenu .menu').prepend(alarmFaultLowHtml);
    } else if (statusAbbr == 4) {
//                	  低电
        $('.lowPowerMenu .menu').prepend(alarmFaultLowHtml);
    }
//  实时显示报警条数
    getDeviceSum();
    getAlarmNum();
    getFaultNum();
    getLowPowerNum();
}

//设置设备总数
function getDeviceSum() {
    var devCount = 0;
    $.ajax({
        url: "/device/count/bydevicetype/001/byuser",
        type: "GET",
        async: false,
        success: function (result) {
            if (result.status == "200") {
                devCount = result.data;
            } else {
            	
            }
        }

    })
    $(".sumSmoke").text(devCount);
    $(".sumSmoke1").text(devCount);
    $(".dataSmokeSum").text(devCount);
}
/* 显示火警报警条数  */
function getAlarmNum() {
    var alarmNum = 0;
    $.ajax({
        url: '/deviceStatus/count/bystatus/1/bydevicetype/001/byuser',
        type: 'get',
        success: function (data) {
            if (data.status == 200) {
                alarmNum = data.data;
                $('.alarmNum').text(alarmNum);
            } else {
                winTip.alert(data.message)
            }
        }
    });
}

/* 显示故障信息条数 */
function getFaultNum() {
    var faultNum = 0;
    $.ajax({
        url: '/deviceStatus/count/bystatus/3/bydevicetype/001/byuser',
        type: 'get',
        success: function (data) {
            if (data.status == 200) {
                faultNum = data.data;
                $('.faultNum').text(faultNum);
            } else {
                winTip.alert(data.message)
            }
        }
    });
}
/* 低电信息条数 */
function getLowPowerNum() {
    var lowPowerNum = 0;
    $.ajax({
        url: '/deviceStatus/count/bystatus/4/bydevicetype/001/byuser',
        type: 'get',
        success: function (data) {
            if (data.status == 200) {
                lowPowerNum = data.data;
                $('.lowPowerNum').text(lowPowerNum);
            } else {
                winTip.alert(data.message)
            }
        }
    });
}

function alarmFaultLowHtml(datas) {
    var deviceStatus = datas.status;
    var deviceName = datas.device.deviceName;
    var address = datas.device.address;
    var returnTimes = datas.returnTime;
    var latitude = datas.device.latitude;
    var longitude = datas.device.longitude
    var devCode = datas.device.devCode;
    var devicecode = datas.device.devCode;
    var latitude = datas.device.latitude;
    var longitude = datas.device.longitude;

    var linkMain1 = datas.device.linkMain1;
    var linkMain2 = datas.device.linkMain2;
    var linkMain3 = datas.device.linkMain3;
    var linkMain4 = datas.device.linkMain4;
    var linkPhone1 = datas.device.linkPhone1;
    var linkPhone2 = datas.device.linkPhone2;
    var linkPhone3 = datas.device.linkPhone3;
    var linkPhone4 = datas.device.linkPhone4;
    var alarmHtml = '<li class="li_device" devicecode="' + devCode + '"'
        + ' latitude = "' + latitude + '"'
        + ' longitude = "' + longitude + '"'
        + ' linkMain1 = "' + linkMain1 + '"'
        + ' linkMain2 = "' + linkMain2 + '"'
        + ' linkMain3 = "' + linkMain3 + '"'
        + ' linkMain4 = "' + linkMain4 + '"'
        + ' linkPhone1 = "' + linkPhone1 + '"'
        + ' linkPhone2 = "' + linkPhone2 + '"'
        + ' linkPhone3 = "' + linkPhone3 + '"'
        + ' linkPhone4 = "' + linkPhone4 + '"'
        + ' deviceStatus = "' + deviceStatus + '"'
        + '><a href="#"><div class="pull-left"><i class="fa fa-map-marker"></i></div><h4 class="deviceName" style="margin-bottom:12px">' + deviceName + '<small><i class="fa fa-clock-o"></i>' + moment(returnTimes).format("YYYY-MM-DD HH:mm:ss") + '</small></h4><p>' + address + '</p></a></li>';

    return alarmHtml;
}

function alarmFaultLow() {
    // 火警信息动态处理
    $('.alarmMenu .menu').html("");
    $('.faultMenu .menu').html("");
    $('.lowPowerMenu .menu').html("");
    $.ajax({
        url: '/deviceStatus/data/list/bystatus/1/bydevicetype/001/byuser',
        type: 'GET',
        success: function (data) {
            if (data.status == 200) {
                for (var i = 0; i < data.data.length; i++) {
                    var datas = data.data[i];
                    $('.alarmMenu .menu').prepend(alarmFaultLowHtml(datas));
                    $('.alarmMenu .menu .fa-map-marker').css("color", "#ff5656")
                }
            } else {
                winTip.alert(data.message)
            }
        }
    });

    // 故障信息动态处理
    $.ajax({
        url: '/deviceStatus/data/list/bystatus/3/bydevicetype/001/byuser',
        type: 'GET',
        success: function (data) {
            if (data.status == 200) {
                for (var i = 0; i < data.data.length; i++) {
                    var datas = data.data[i];
                    $('.faultMenu .menu').prepend(alarmFaultLowHtml(datas));
                    $('.faultMenu .menu .fa-map-marker').css("color", "#b5b5b5")
                }
            } else {
                winTip.alert(data.message)
            }
        }
    });


    // 低电信息动态处理
    $.ajax({
        url: '/deviceStatus/data/list/bystatus/4/bydevicetype/001/byuser',
        type: 'GET',
        success: function (data) {
            if (data.status == 200) {
                for (var i = 0; i < data.data.length; i++) {
                    var datas = data.data[i];
                    $('.lowPowerMenu .menu').prepend(alarmFaultLowHtml(datas));
                    $('.lowPowerMenu .menu .fa-map-marker').css("color", "#ff9900")
                }
            } else {
                winTip.alert(data.message)
            }
        }
    });
}

//历史信息按钮闪烁时，点击则隐藏
$(function () {

//    点击下拉框定位地图
    $(".slimScrollDiv").on('click', '.li_device', function (e) {
//    	$(this).siblings().
        //hideOver();
        //e.stopPropagation();   
        var li = $(this);
        var devicecode = li.attr("devicecode");
        var latitude = li.attr("latitude");
        var longitude = li.attr("longitude");
        var deviceStatus = li.attr("deviceStatus");
        map.setZoom(20);
        BaiDuMap.panTo(latitude, longitude);
//        地图信息框显示
        $('.BMap_pop').parent().show();
        $(".BMap_shadow").parent().show();
        setTimeout(function () {
            BaiDuMap.popMenu(devicecode);
        }, 0);
//        popMenu(devicecode);
    });
    /*    $(".sumStyle").click(function () {
     $("#smokeDetector").addClass("selected");
     });
     $('.historyBgc').on('click', function () {
     $("#smokeDetector").addClass("selected");
     });*/


});



